package online.afeibaili.storebackendframework.other

import online.afeibaili.storebackendframework.af.UserInterface
import online.afeibaili.storebackendframework.model.AccountEntity
import online.afeibaili.storebackendframework.service.impl.AccountServiceImpl
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component


/**
 * 用户实现接口
 *
 *@author AfeiBaili
 *@version 2025/11/6 10:32
 */

@Component
class UserInterfaceImpl : UserInterface {

    @Autowired
    lateinit var accountServiceImpl: AccountServiceImpl

    override fun selectUser(): List<Map<String, Any>> {
        val entities: List<AccountEntity> = accountServiceImpl.getAll()
        return toListMap(entities)
    }

    override fun selectUserById(ids: List<String>): List<Map<String, Any>> {
        val entities: List<AccountEntity> = accountServiceImpl.getByIds(ids)
        return toListMap(entities)
    }

    fun toListMap(entities: List<AccountEntity>): List<Map<String, Any>> =
        mutableListOf<Map<String, Any>>().apply {
            entities.forEach { acc -> add(mapOf("user" to acc.nickname, "userId" to acc.id)) }
        }
}